package com.example.bookstore.controller;

import com.example.bookstore.common.PageResult;
import com.example.bookstore.common.Result;
import com.example.bookstore.dto.QueryCartParamsDto;
import com.example.bookstore.entity.Book;
import com.example.bookstore.entity.Cart;
import com.example.bookstore.service.CartService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;

    @PutMapping
    public Result<String> addCart(@RequestBody Cart cart) {
        Result<String> stringResult = cartService.addCart(cart);
        return stringResult;
    }

    @PostMapping("/page")
    public PageResult<Cart> selectCart(int pageSize, int currentPage, @RequestBody QueryCartParamsDto params) {
        return cartService.selectCart(pageSize, currentPage, params);
    }

    @GetMapping("/quantity")
    public Result updateQuantity(int quantity, int id) {
        return cartService.updateQuantity(quantity, id);
    }

    @DeleteMapping()
    public Result deleteCart(@RequestBody List<Integer> ids) {
        return cartService.deleteCarts(ids);
    }
}
